from sqlalchemy import Column, Integer, String, Text, DateTime, ForeignKey
from sqlalchemy.sql import func
from app.database import Base

class Comment(Base):
    __tablename__ = "comments"

    id = Column(Integer, primary_key=True, index=True)
    content = Column(Text, nullable=False)
    
    # 关联的实体类型和ID（通用关联，支持issue、case等）
    entity_type = Column(String(50), nullable=False)  # issue, case, etc.
    entity_id = Column(Integer, nullable=False)
    
    # 评论者
    author_id = Column(Integer, ForeignKey("users.id"), nullable=False)
    
    # 父评论ID，支持多级评论
    parent_id = Column(Integer, ForeignKey("comments.id"), nullable=True)
    
    created_at = Column(DateTime, server_default=func.now())
    updated_at = Column(DateTime, server_default=func.now(), onupdate=func.now())